const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

function errImgFun(e, that,src) {
  var _errImg = e.target.dataset.errImg;
  var _errObj = {};
  _errObj[_errImg] = src;
  that.setData(_errObj);
}

const isEmpty = (value) => {
  let type
  if (value == null) {
    return true
  }
  type = Object.prototype.toString.call(value).slice(8, -1)
  switch (type) {
    case 'String':
      return value.length === 0
    case 'Array':
      return !value.length
    case 'Object':
      return Object.keys(value).length === 0 && value.constructor === Object
    default:
      return false
  }
}


module.exports = {
  formatTime: formatTime
}

module.exports = {
  formatTime: formatTime,
  errImgFun: errImgFun,
  isEmpty: isEmpty
}
